#!/bin/bash

# ============================================
# 修复前端静态资源 404 问题
# ============================================

echo "=== 检查 dist 目录 ==="
cd /mnt/lwy/django-vue3-admin/web
pwd
ls -la dist/ | head -10

echo ""
echo "=== 检查 assets 目录 ==="
ls -la dist/assets/ 2>/dev/null | head -5 || echo "assets 目录不存在或为空"

echo ""
echo "=== 检查 Nginx 配置中的 root 路径 ==="
grep "root" /etc/nginx/conf.d/frontend.conf

echo ""
echo "=== 验证路径是否存在 ==="
ROOT_PATH=$(grep "root" /etc/nginx/conf.d/frontend.conf | head -1 | awk '{print $2}' | sed 's/;$//')
echo "Nginx root 路径: $ROOT_PATH"

if [ -d "$ROOT_PATH" ]; then
    echo "✓ 路径存在"
    ls -la "$ROOT_PATH" | head -5
else
    echo "✗ 路径不存在"
fi

echo ""
echo "=== 检查文件是否存在 ==="
if [ -f "$ROOT_PATH/assets/index.C4RlbeGH.js" ]; then
    echo "✓ 文件存在"
else
    echo "✗ 文件不存在"
    echo "查找类似的文件："
    find "$ROOT_PATH/assets" -name "index.*.js" 2>/dev/null | head -3
fi

echo ""
echo "=== 修复方案 ==="
echo "1. 确认 dist 目录路径："
echo "   cd /mnt/lwy/django-vue3-admin/web && ls -la dist/"
echo ""
echo "2. 更新 Nginx 配置中的 root 路径（如果需要）"
echo ""
echo "3. 检查文件权限："
sudo ls -la /mnt/lwy/django-vue3-admin/web/dist/ | head -5

